We are migrating the bug tracker to github Issues. This is now the preferred way to report NASM bugs.

Self-registration is disabled due to spam issue (mail gorcunov@gmail.com or hpa@zytor.com to create an account)

Bug 3392721 - Problems with very large resb and times counts
Summary: Problems with very large resb and times counts
Status: OPEN
Alias: None
Product: NASM
Classification: Unclassified
Component: Assembler (show other bugs)
Version: 2.15.xx
Hardware: All All
: Medium normal
Assignee: nobody
URL:
Depends on:
Blocks:
 
Reported: 2020-10-30 12:06 PDT by E. C. Masloch
Modified: 2020-11-01 12:28 PST (History)
5 users (show)

Obtained from: Built from git using configure
Generated by: ---
Bug category:
Observed for: ---
Regression: ---
Regression since:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description E. C. Masloch 2020-10-30 12:06:37 PDT
Both resb and times fail in a panic if given a count of at least 8000_0000h. I made a workaround to use a %rep loop around individual statements which are given counts below the limit.

Times needs 40 times the duration needed by resb. Even though resb is technically only for reserving uninitialised space, I'm using it to zero-initialise large runs of space in one of my programs. I disabled the zeroing warning around this use of resb.

Source for both aspects can be found at https://hg.ulukai.org/ecm/bootimg/file/69c5556a61a6/bootimg.asm#l124

Here's some tests. Note that I aborted the -DTIMES=7FFF_FFFFh (2 GiB) run because it took much longer (more than 20 minutes, 60 times the duration of the -D_TIMES=800_0000h (128 MiB) run) and appeared not to finish. In an earlier run I did (not shown here) I let it run for more than 500 minutes without it terminating.

(I'm aware NASM is not intended to create multi-GiB output files but apart from these problems it woks fine.)

$ nasm -v
NASM version 2.15.03rc1 compiled on Sep 30 2020
$ (cd ~/proj/nasm; git describe)
nasm-2.15.01-53-g91bc5188
$ cat test.asm

%ifdef TIMES
 times TIMES db 0
%endif

%ifdef RESB
 resb RESB
%endif
$ time nasm test.asm -DRESB=8000_0000h
panic: test.asm:7: assertion data.inslen >= 0 failed at asm/assemble.c:880

real    0m0.005s
user    0m0.002s
sys     0m0.003s
$ time nasm test.asm -DTIMES=8000_0000h
panic: test.asm:3: assertion instruction->times > 0 failed at asm/nasm.c:1581

real    0m0.003s
user    0m0.001s
sys     0m0.003s
$ time nasm test.asm -DRESB=7FFF_FFFFh
test.asm:7: warning: uninitialized space declared in .text section: zeroing [-w+zer
oing]

real    0m11.082s
user    0m0.527s
sys     0m5.507s
$ time nasm test.asm -DTIMES=800_0000h

real    0m19.312s
user    0m18.613s
sys     0m0.519s
$ time nasm test.asm -DTIMES=7FFF_FFFFh
^C
real    21m10.861s
user    20m58.930s
sys     0m1.347s

$ time nasm test.asm -DRESB=800_0000h
test.asm:7: warning: uninitialized space declared in .text section: zeroing [-w+zer
oing]

real    0m0.364s
user    0m0.032s
sys     0m0.320s
$
Comment 1 E. C. Masloch 2020-11-01 03:27:29 PST
Here's an example command using the bootimg script and lmacros to create an empty 1 GiB image file. (I tried 10 GiB first but that currently seems to crash on the server. 1 GiB is enough for testing LBA access on dosemu2 anyway, as the CHS geometry heads and sectors are both lower than the maximum.)

bootimg$ time nasm bootimg.asm -D_MBR -D_MBR_DOSEMU_IMAGE_HEADER -o test.img -D_UNIT=80h -D_PAYLOADFILE=::empty -I ../lmacros/ -D_CHS_HEADS=16 -D_CHS_SECTORS=32 -D_BPE=32 -D_SPC=1 -D_SPI=$(( 1024 * 2 * 1024 )) -D_SPF=$(( (1024 * 2 * 1024 * 4 + 511) / 512 )) -l test.lst

real    0m5.368s
user    0m0.284s
sys     0m2.612s
bootimg$ grep odhex ~/.bashrc
function odhex() { od -Ax -tx1z "$@" | perl -pe 's/([0-9A-Fa-f]+ +([0-9A-Fa-f]+ +)+)/uc($1)/eg;s/^([0-9A-F]+(?: +[0-9A-F]+){8}) /$1-/g'; }
bootimg$ odhex test.img
000000 44 4F 53 45 4D 55 00 10-00 00 00 20 00 00 00 01  >DOSEMU..... ....<
000010 10 00 00 00 20 00 00 00-00 00 00 00 00 00 00 00  >.... ...........<
000020 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
002000 FA FC 31 C0 8E C0 8E D8-8E D0 BC 00 7C FB BE 2C  >..1.........|..,<
002010 7C AC 84 C0 74 0C B4 0E-8A 3E 62 04 B3 07 CD 10  >|...t....>b.....<
002020 EB EF 31 C0 CD 13 31 C0-CD 16 CD 19 55 6E 61 62  >..1...1.....Unab<
002030 6C 65 20 74 6F 20 62 6F-6F 74 2C 20 4D 42 52 20  >le to boot, MBR <
002040 6C 6F 61 64 65 72 20 6E-6F 74 20 77 72 69 74 74  >loader not writt<
002050 65 6E 2E 0D 0A 0D 0A 50-72 65 73 73 20 61 6E 79  >en.....Press any<
002060 20 6B 65 79 20 74 6F 20-72 65 62 6F 6F 74 2E 0D  > key to reboot..<
002070 0A 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
002080 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
0021B0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 80 00  >................<
0021C0 01 01 01 0F E0 FF 00 02-00 00 00 00 20 00 00 00  >............ ...<
0021D0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
0021F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA  >..............U.<
002200 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
042000 EB 58 90 20 20 20 20 6C-44 4F 53 00 02 01 08 00  >.X.    lDOS.....<
042010 02 00 00 00 00 F0 00 00-20 00 10 00 00 02 00 00  >........ .......<
042020 00 00 20 00 00 40 00 00-00 00 00 00 02 00 00 00  >.. ..@..........<
042030 01 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
042040 80 00 29 00 00 00 00 4E-4F 20 4E 41 4D 45 20 20  >..)....NO NAME  <
042050 20 20 46 41 54 33 32 20-20 20 FA FC 31 C0 8E C0  >  FAT32   ..1...<
042060 8E D8 8E D0 BC 00 7C FB-BE 86 7C AC 84 C0 74 0C  >......|...|...t.<
042070 B4 0E 8A 3E 62 04 B3 07-CD 10 EB EF 31 C0 CD 13  >...>b.......1...<
042080 31 C0 CD 16 CD 19 55 6E-61 62 6C 65 20 74 6F 20  >1.....Unable to <
042090 62 6F 6F 74 2C 20 6C 6F-61 64 65 72 20 6E 6F 74  >boot, loader not<
0420A0 20 77 72 69 74 74 65 6E-2E 0D 0A 0D 0A 50 72 65  > written.....Pre<
0420B0 73 73 20 61 6E 79 20 6B-65 79 20 74 6F 20 72 65  >ss any key to re<
0420C0 62 6F 6F 74 2E 0D 0A 00-00 00 00 00 00 00 00 00  >boot............<
0420D0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
0421F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA  >..............U.<
042200 52 52 61 41 00 00 00 00-00 00 00 00 00 00 00 00  >RRaA............<
042210 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
0423E0 00 00 00 00 72 72 41 61-FF FF FF FF FF FF FF FF  >....rrAa........<
0423F0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 55 AA  >..............U.<
042400 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
043000 F0 FF FF 0F FF FF FF 0F-FF FF FF 0F 00 00 00 00  >................<
043010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
843000 F0 FF FF 0F FF FF FF 0F-FF FF FF 0F 00 00 00 00  >................<
843010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00  >................<
*
40042000
bootimg$
Comment 2 H. Peter Anvin 2020-11-01 12:28:28 PST
This is quite correct... unfortunately there are a large number of places in the NASM codebase where a length is represented by a signed int32_t.

It is only relatively recently that NASM even had ways to represent sparse files internally without blowing up (and it still will unless you are in a nobits segment.)
Comment 3 H. Peter Anvin 2020-11-01 12:28:48 PST
This is quite correct... unfortunately there are a large number of places in the NASM codebase where a length is represented by a signed int32_t.

It is only relatively recently that NASM even had ways to represent sparse files internally without blowing up (and it still will unless you are in a nobits segment.)